package ce.com.cenewbluesdk.entity.k2;



import android.os.Parcel;
import android.os.Parcelable;

import java.util.Arrays;

/**
 * Created by Administrator on 2016/11/21.
 *{
 * unsigned char devHWVer;	//设备硬件版本号版本号 4bit – 4bit显示
 * unsigned char devSWVer;	//设备软件版本号版本号
 * }dev_info_struct;
 */
public class K2_DevInfoStruct implements Parcelable {
    private static final long serialVersionUID = 3765629512912029068L;

    public final static int devInfoByteLen = 6;


    private int  items;	 //ID条目的总数
    private int  customer_id;	//客户ID
    private int  hardware_id;	//硬件ID
    private int  code_id;	 //代码ID
    private int  picture_id;	//图片ID
    private int  font_id;	 //字库ID



    String hardwareVer;
    String softwareVer;

    public K2_DevInfoStruct() {
    }

    public K2_DevInfoStruct(int items, int customer_id,
                            int hardware_id,
                            int code_id,
                            int picture_id,
                            int font_id
    ) {
        this.items = items;
        this.customer_id = customer_id;
        this.hardware_id = hardware_id;
        this.code_id = code_id;
        this.picture_id = picture_id;
        this.font_id = font_id;
        this.hardwareVer = hardware_id+"";
        this.softwareVer = customer_id+"."+hardware_id+"."+code_id+"."+picture_id+"."+font_id;
    }

    protected K2_DevInfoStruct(Parcel in) {
        items = in.readInt();
        customer_id = in.readInt();
        hardware_id = in.readInt();
        code_id = in.readInt();
        picture_id = in.readInt();
        font_id = in.readInt();
        hardwareVer = in.readString();
        softwareVer = in.readString();
    }

    public static final Creator<K2_DevInfoStruct> CREATOR = new Creator<K2_DevInfoStruct>() {
        @Override
        public K2_DevInfoStruct createFromParcel(Parcel in) {
            return new K2_DevInfoStruct(in);
        }

        @Override
        public K2_DevInfoStruct[] newArray(int size) {
            return new K2_DevInfoStruct[size];
        }
    };

    public byte[] getBytes() {

        byte[] bytes = new byte[6];
        bytes[0] = (byte) items;
        bytes[1] = (byte)customer_id;
        bytes[2] = (byte)hardware_id;
        bytes[3] = (byte)code_id;
        bytes[4] = (byte)picture_id;
        bytes[5] = (byte)font_id;

        return bytes;
    }

    public static K2_DevInfoStruct parseDevInfo(byte[] devInfoBytes) {
        System.out.println("收到的设备信息字节:" + Arrays.toString(devInfoBytes));

        K2_DevInfoStruct devInfo = new K2_DevInfoStruct(devInfoBytes[0] & 0xff, devInfoBytes[1] & 0xff,
                devInfoBytes[2] & 0xff,devInfoBytes[3] & 0xff,devInfoBytes[4] & 0xff,devInfoBytes[5] & 0xff   );
        return devInfo;
    }

    @Override
    public String toString() {
        return "Dev_Info_Struct_K3{" +
                "hardwareVer='" + hardwareVer + '\'' +
                ", softwareVer='" + softwareVer + '\'' +
                '}';
    }

    public String getHardwareVer() {
        return hardwareVer;
    }

    public String getSoftwareVer() {
        return softwareVer;
    }

    public static int getItemSize() {
        return 6;
    }

    public int getCustomer_id() {
        return customer_id;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(items);
        dest.writeInt(customer_id);
        dest.writeInt(hardware_id);
        dest.writeInt(code_id);
        dest.writeInt(picture_id);
        dest.writeInt(font_id);
        dest.writeString(hardwareVer);
        dest.writeString(softwareVer);
    }
}
